<?php
class GenreControl extends CI_Controller {

	function __construct() 
	{		
		parent::__construct();
		$this->load->model('genresmodel');
		$this->load->model('moviesmodel');
		$this->load->model('genredominanmodel');
	}
	
//	function index() {
//		$genre = $this->genredominanmodel->getAllGenre()->result();
//		$this->showMovieGenre(current($genre));
//	}
	
	function index(){
		$genre = $this->genredominanmodel->getAllGenre()->result();
		$movie = $this->moviesmodel->getAllMovies()->result();
		$m = 0;
		for ($i = 0; $i < count($movie); $i++) {
			$dom[$i] = false;
			for ($j = 0; $j < count($genre); $j++) { //untuk mengecek genre nya
				$gen = $this->genresmodel->getGenre($movie[$i]->MOVIEID)->result();
				for ($j2 = 0; $j2 < count($gen); $j2++) {
					if ($gen[$j2]->GENRE == $genre[$j]->GENREDOM) {
						$dom[$i] = true;
					}
				}
			}
			
			if ($dom[$i] == true) {
				$moviedom['detail'][$m] = $this->moviesmodel->getDataMovie($movie[$i]->MOVIEID)->result();
				$moviedom['genre'][$m] = $this->genresmodel->getGenre($movie[$i]->MOVIEID)->result();
				$m = $m + 1;
			}
		}
		$this->load->view('genrepage', $moviedom);
//		$c = 0;
//		for ($i = 0; $i < sizeof($genre); $i++) {
//			$movie = $this->genresmodel->getMovieId($genre[$i]->GENREDOM)->result();
//			for ($j = 0; $j < sizeof($movie); $j++) {
//				$moviedom['detail'][$c+$j] = $this->moviesmodel->getDataMovie($movie[$j]->MOVIEID)->result();
//				$moviedom['genre'][$c+$j] = $this->genresmodel->getGenre($movie[$j]->MOVIEID)->result();
//			}
//			$c = $c + sizeof($movie);
//			
//		}
//		$this->load->view('genrepage', $moviedom);
	

//		echo $genre[0]->GENREID;
			
	}
	
	function submitGenre($genre) {
		if ($this->input->post('submit')) {
//			$this->rekomendasimodel->saveRecommendation($userid, $movieid);
			return next($genre);
			redirect('genrecontrol/index', 'refresh');
		}
	}
}
?>